package com.raowb.common.util;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;

/**
 * 分页工具类
 *
 * @author RaoWenbiao
 * 
 * @date 2016年11月4日 下午12:59:00
 */
public class Page implements Serializable {
	private static final long serialVersionUID = 1L;
	// 总记录数
	private int totalCount;
	// 每页记录数
	private int pageSize;
	// 总页数
	private int totalPage;
	// 当前页数
	private int pageNo;

	// 升序字段
	private String[] ascs;
	// 降序字段
	private String[] descs;

	// 列表数据
	private List<?> list;

	public Page() {
		this.list = Collections.emptyList();
		this.totalCount = 0;
		this.pageSize = 0;
		this.pageNo = 1;
	}

	public Page(int pageSize, int pageNo) {
		this.pageSize = pageSize;
		this.pageNo = pageNo;
	}

	/**
	 * 分页
	 *
	 * @param list       列表数据
	 * @param totalCount 总记录数
	 * @param pageSize   每页记录数
	 * @param currPage   当前页数
	 */
	public Page(List<?> list, int totalCount, int pageSize, int pageNo) {
		this.list = list;
		this.totalCount = totalCount;
		this.pageSize = pageSize;
		this.pageNo = pageNo;
		this.totalPage = (int) Math.ceil((double) totalCount / pageSize);
	}

	public int getTotalCount() {
		return totalCount;
	}

	public Page setTotalCount(int totalCount) {
		this.totalCount = totalCount;
		return this;
	}

	public int getPageSize() {
		return pageSize;
	}

	public Page setPageSize(int pageSize) {
		this.pageSize = pageSize;
		return this;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public Page setTotalPage(int totalPage) {
		this.totalPage = totalPage;
		return this;
	}

	public int getPageNo() {
		return pageNo;
	}

	public Page setPageNo(int pageNo) {
		this.pageNo = pageNo;
		return this;
	}

	public List<?> getList() {
		return list;
	}

	public Page setList(List<?> list) {
		this.list = list;
		return this;
	}

	public Page setAscs(List<String> ascs) {
		if (CollectionUtils.isNotEmpty(ascs)) {
			this.ascs = ((String[]) ascs.toArray(new String[0]));
		}
		return this;
	}

	public Page setDescs(List<String> descs) {
		if (CollectionUtils.isNotEmpty(descs)) {
			this.descs = ((String[]) descs.toArray(new String[0]));
		}
		return this;
	}

	public String[] getAscs() {
		return ascs;
	}

	public String[] getDescs() {
		return descs;
	}

}
